﻿using FluentAssertions;

using NewModel.Accounting.Calculation;
using NewModel.Accounting.Core;

using NUnit.Framework;

namespace NewModel.UnitTests.Accounting.Calculation
{
    [TestFixture]
    public sealed class TestMoneyBag
    {
        readonly Money m20Usd = new Money(Currency.Usd, 20);
        readonly Money m5Eur = new Money(Currency.Eur, 5);

        MoneyBag mUnderTest;

        [SetUp]
        public void SetUp()
        {
            mUnderTest = new MoneyBag(m20Usd, m5Eur);
        }

        [Test]
        public void Indexer_Should_Return_Amount()
        {
            mUnderTest[Currency.Usd].Should().Be(20);
            mUnderTest[Currency.Eur].Should().Be(5);
        }

        [Test]
        public void Indexer_When_No_Such_Currency_Should_Return_0()
        {
            mUnderTest[new Currency()].Should().Be(0);
        }
        [Test]
        public void Unary_Negation_Should_Invert_Amounts()
        {
            (-mUnderTest)[Currency.Usd].Should().Be(-20);
            (-mUnderTest)[Currency.Eur].Should().Be(-5);
        }		
        [Test]
        public void Addition_Should_Add_Amounts()
        {
            var result = new MoneyBag(m20Usd) + new MoneyBag(m5Eur);
            result[Currency.Usd].Should().Be(20);
            result[Currency.Eur].Should().Be(5);
        }
        [Test]
        public void Subtraction_Should_Subtract_Amounts()
        {
            var result = new MoneyBag(m20Usd) - new MoneyBag(m20Usd, m5Eur);
            result.ShouldAllBeEquivalentTo(new []{-m5Eur});
        }
    }
}